//
//  UserDefault+Extension.swift
//  SmartEyeForDoctor
//
//  Created by QDSG on 2021/4/29.
//

import Foundation

extension UserDefaults {
    
    struct Name {
        static let authToken = "authToken"
        static let userAccount = "userAccount"
        static let xylinkAccount = "xylinkAccount"
        static let userId = "userId"
        static let userFemale = "userFemale"
        static let jpushRegistrationId = "jpushRegistrationId"
        static let remberAccountAndPsd = "remberAccountAndPsd"
    }

    // MARK: - 用户登录token

    /// token
    static var authToken: String {
        get { UserDefaults.standard.string(forKey: Name.authToken) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: Name.authToken)
            UserDefaults.standard.synchronize()
        }
    }
    
    /// 清除token
    static func removeAuthToken() {
        UserDefaults.standard.removeObject(forKey: Name.authToken)
        UserDefaults.standard.synchronize()
    }

    // MARK: - 用户名

    /// 获取用户名
    static var userAccount: String {
        get { UserDefaults.standard.string(forKey: Name.userAccount) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: Name.userAccount)
            UserDefaults.standard.synchronize()
        }
    }

    /// 清除用户名
    static func removeUserAccount() {
        UserDefaults.standard.removeObject(forKey: Name.userAccount)
        UserDefaults.standard.synchronize()
    }

    // MARK: - XYLINK账号

    /// XYLINK账号
    static var xylinkAccount: String {
        get { UserDefaults.standard.string(forKey: Name.xylinkAccount) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: Name.xylinkAccount)
            UserDefaults.standard.synchronize()
        }
    }

    /// 清除XYLINK账号
    static func removeXylinkAccount() {
        UserDefaults.standard.removeObject(forKey: Name.xylinkAccount)
        UserDefaults.standard.synchronize()
    }

    // MARK: - 用户ID

    /// 用户ID
    static var userId: String {
        get { UserDefaults.standard.string(forKey: Name.userId) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: Name.userId)
            UserDefaults.standard.synchronize()
        }
    }
    
    /// 用户性别 true - 女 false - 男
    static var userFemale: Bool {
        get { UserDefaults.standard.bool(forKey: Name.userFemale) }
        set {
            UserDefaults.standard.set(newValue, forKey: Name.userFemale)
            UserDefaults.standard.synchronize()
        }
    }

    /// 清除用户ID
    static func removeUserId() {
        UserDefaults.standard.removeObject(forKey: Name.userId)
        UserDefaults.standard.synchronize()
    }

    // MARK: - 极光注册ID

    /// 极光注册ID
    static var jpushRegistrationId: String {
        get { UserDefaults.standard.string(forKey: Name.jpushRegistrationId) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: Name.jpushRegistrationId)
            UserDefaults.standard.synchronize()
        }
    }

    /// 清除极光注册ID
    static func removeJpushRegistrationId() {
        UserDefaults.standard.removeObject(forKey: Name.jpushRegistrationId)
        UserDefaults.standard.synchronize()
    }


    // MARK: - 是否记住用户名密码

    /// 是否记住用户名密码
    static var remberAccountAndPsd: Bool {
//        get { UserDefaults.standard.bool(forKey: Name.remberAccountAndPsd)}
        get {
            true
        }
        set {
            UserDefaults.standard.set(newValue, forKey: Name.remberAccountAndPsd)
            UserDefaults.standard.synchronize()
        }
    }

}
